package com.hub.wc;

import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class StreamWordCount {

    public static void main(String[] args) throws Exception {

        // 使用parameter tool工具从程序启动参数中提取配置项
//        ParameterTool parameterTool = ParameterTool.fromArgs(args);
//        String host = parameterTool.get("host");
//        int port = parameterTool.getInt("port");
//        System.out.println("监听地址： IP:" + host + ", PORT:" + port);
        // 创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 数据集
        DataStream<String> inputDataStream = env.socketTextStream("119.23.58.27", 8082);

        //
        DataStream<Tuple2<String, Integer>> output = inputDataStream
                .flatMap(new MyFlatMapFunction())
                .keyBy(0)
                .sum(1);

        output.print();
        env.execute();

    }


}
